/*
* Copyright (c) 2016 . All Rights Reserved.
*/
package com.cgmnx.admin.web.converter.entity;

import com.cgmnx.admin.common.bean.CurrentUserInfo;
import com.cgmnx.admin.common.bean.UserContext;
import com.cgmnx.admin.common.constants.WebConstant;
import com.cgmnx.admin.dao.entity.rbac.RoleEntity;
import com.cgmnx.admin.web.converter.Convert;
import com.cgmnx.admin.web.model.param.RoleParam;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: created  Date: 16/12/13 Time: 下午6:32
 * @version: 1.0
 */
@Component
public class RoleEntityConverter implements Convert<RoleParam, RoleEntity> {
    @Override
    public RoleEntity convert(RoleParam input) {

        if (input == null) {
            return null;
        }

        RoleEntity entity = new RoleEntity();

        entity.setName(input.getRoleName());
        entity.setDescription(input.getDesc());
        entity.setId(input.getId());
        CurrentUserInfo userInfo = UserContext.getUserInfo();
        if (userInfo != null) {
            entity.setCreateUser(userInfo.getUserId());
            entity.setUpdateUser(userInfo.getUserId());
        } else {
            entity.setCreateUser(WebConstant.CURRENT_LOGIN_USER);
            entity.setUpdateUser(WebConstant.CURRENT_LOGIN_USER);
        }

        return entity;
    }

    @Override
    public List<RoleEntity> convert(List<RoleParam> t) {
        return null;
    }
}